package com.ssm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssm.pojo.Company;
import com.ssm.pojo.Employment;
import com.ssm.pojo.Person;
import com.ssm.service.CompanyService;
import com.ssm.service.DoService;
import com.ssm.service.EmploymentService;
import com.ssm.service.PersonService;
import com.ssm.service.PositionService;
import com.ssm.service.impl.EmploymentServiceImpl;

@Controller
@RequestMapping("/do")
public class DoController {
	@Resource
	private DoService doServiceImpl;
	@Resource
	private PersonService personServiceImpl;
	@Resource
	private CompanyService companyServiceImpl;
	@Resource
	private PositionService positionServiceImpl;
	@Resource
	private EmploymentService employmentServiceImpl;
	
	
	
	
	
	@RequestMapping(value="/toujianli")
	public void toujianli(Employment em,HttpServletResponse resp) throws IOException{
		Person person = personServiceImpl.selectbyid(em.getpId());
		Company company = companyServiceImpl.selectbyid(em.getcId());
	//	System.out.println(em);
		em.setcName(company.getName());
		em.setpName(person.getName());
	//	System.out.println(em.getpId()+":"+ em.getcId());
		Employment employment = doServiceImpl.chaxun(em.getzId(),em.getpId(), em.getcId());
		System.out.println(employment);
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out = resp.getWriter();
		if(employment==null){
			int index = doServiceImpl.toujianli(em);
			if(index>0){
				out.println("投递成功");
				
				
			}else{
				out.println("服务器繁忙，请稍候在试");
				
			}
		}else{
			
			out.println("你已经投递了，请勿在投！");
			
		}
		out.flush();
		out.close();
		
	}
	
	@RequestMapping(value="/delposition")
	public void delposition(int zId ,HttpServletResponse resp) throws IOException{
		int index = positionServiceImpl.delposition(zId);
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out = resp.getWriter();
		if(index>0){
			out.println("删除成功");
		}else{
			out.println("服务器繁忙，请稍候在试");
			
		}
		
	}
	
	
	@RequestMapping(value="/accept1")
	public void accept1(Employment em ,HttpServletResponse resp) throws IOException{
		int index = employmentServiceImpl.updatestate(em);
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out = resp.getWriter();
		if(index>0){
			out.println("接受成功");
		}else{
			out.println("服务器繁忙，请稍候在试");
			
		}
		
	}

}
